/* global resetActive addClass removeClass
*/

// 给性别加上绑定函数
function bindtag() {
	let male = document.getElementsByClassName('male')[0];
	let female = document.getElementsByClassName('female')[0];
	male.addEventListener("click", function() {
		resetActive();
		addClass(male,'active');
	});
	female.addEventListener("click", function() {
		resetActive();
		addClass(female,'active');
	});
}
bindtag();

// 检测容器下面所有选中的checkbox并取得他们的id，给他们同样id的容器加上active
function addActive() {
	let tagparent = document.getElementsByClassName('many')[0];
	let tag = tagparent.getElementsByTagName('input');
	let length = tag.length;
	for( let i = 0; i != length ; i++) {
		if (tag[i].checked === true) {
			let tagid = tag[i].id;
			let tagdom = document.getElementsByClassName(tagid)[0];
			addClass(tagdom,'active');
		} else {
			let tagid = tag[i].id;
			let tagdom = document.getElementsByClassName(tagid)[0];
			removeClass(tagdom,'active');
		}
	}
}


document.addEventListener('click', function() {
	addActive();
});